import 'package:situation/app/router/router_name.dart';
import 'package:situation/app/theme/app_theme.dart';
import 'package:situation/app/theme/gaps.dart';
import 'package:situation/shared/util/util_mk.dart';
import 'package:situation/widgets/mk_scroll_view.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';

import '../auth_field.dart';
import 'controller.dart';

class AuthForgotPwdPage extends StatefulWidget {
  const AuthForgotPwdPage({Key? key}) : super(key: key);

  @override
  State<AuthForgotPwdPage> createState() => _AuthForgotPwdPageState();
}

class _AuthForgotPwdPageState extends State<AuthForgotPwdPage> {
  final controller = Get.find<AuthForgotPwdController>();
  final state = Get.find<AuthForgotPwdController>().state;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.transparent,
      appBar: TDNavBar(
        backgroundColor: Colors.transparent,
      ),
      body: MkScrollView(
        keyboardConfig: UtilMk.getKeyboardActionsConfig(context, <FocusNode>[
          controller.nodeText1,
          controller.nodeText2,
          controller.nodeText3,
          controller.nodeText4
        ]),
        padding: const EdgeInsets.only(
            left: AppTheme.iDefaultPadding,
            right: AppTheme.iDefaultPadding,
            top: AppTheme.iDefaultPadding * 2),
        children: _buildBody,
      ),
    );
  }

  List<Widget> get _buildBody => <Widget>[
        Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Center(
              child: Text(
                '忘记密码',
                style: TextStyle(fontSize: 32, fontWeight: FontWeight.bold),
              ),
            ),
            Center(
              child: Text(
                '忘记/找回密码',
                style: TextStyle(fontSize: 13),
              ),
            ),
          ],
        ),
        Gaps.vGap32,
        AuthField(
          key: const Key('phone'),
          focusNode: controller.nodeText1,
          controller: controller.phoneController,
          maxLength: 11,
          keyboardType: TextInputType.number,
          hintText: '手机号',
        ),
        Gaps.vGap24,
        AuthField(
          key: const Key('code'),
          keyName: 'password',
          focusNode: controller.nodeText2,
          controller: controller.codeController,
          hintText: '验证码',
          keyboardType: TextInputType.number,
          getVCode: controller.getVCode,
        ),
        Gaps.vGap24,
        AuthField(
          focusNode: controller.nodeText3,
          controller: controller.passwordController,
          maxLength: 16,
          isInputPwd: true,
          keyboardType: TextInputType.text,
          hintText: '密码',
        ),
        Gaps.vGap24,
        AuthField(
          focusNode: controller.nodeText4,
          controller: controller.rePasswordController,
          maxLength: 16,
          isInputPwd: true,
          keyboardType: TextInputType.text,
          hintText: '确认密码',
        ),
        Gaps.vGap24,
        Obx(() => TDButton(
              theme: TDButtonTheme.primary,
              shape: TDButtonShape.circle,
              height: 50,
              width: Get.width,
              key: const Key('login'),
              onTap: state.clickable ? controller.foundPwd : null,
              disabled: !state.clickable,
              text: '找回密码',
            )),
        Gaps.vGap16,
      ];

  _buildCheckbox() {
    TextStyle style = TextStyle(color: TDTheme.of(Get.context!).brandColor5);

    return Row(
      mainAxisAlignment: MainAxisAlignment.start,
      children: [
        Obx(() => TDCheckbox(
              backgroundColor: Colors.transparent,
              checked: state.checkboxIsCheck,
            )),
        Gaps.hGap4,
        Text(
          "我已同意",
        ),
        GestureDetector(
          onTap: () => {Get.toNamed(RouterName.userSystemSettingUserAgreement)},
          child: Text(
            "《用户协议》",
            style: style,
          ),
        ),
        Text("及"),
        GestureDetector(
          onTap: () => {Get.toNamed(RouterName.userSystemSettingPrivacy)},
          child: Text(
            "《隐私政策》",
            style: style,
          ),
        ),
      ],
    );
  }

  @override
  void dispose() {
    Get.delete<AuthForgotPwdController>();
    super.dispose();
  }
}
